package com.lzh.persevere.controller;

import com.lzh.persevere.common.R;
import com.lzh.persevere.common.ResultUtil;
import com.lzh.persevere.model.entity.MusicPlayer;
import com.lzh.persevere.model.qo.ModuleIdQO;
import com.lzh.persevere.model.qo.music.MusicPageQO;
import com.lzh.persevere.model.vo.music.MusicPlayerVO;
import com.lzh.persevere.service.MusicPlayerService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 音乐播放器controller
 *
 * @author luzhiheng
 * @since 2025-07-12
 */
@RestController
@RequestMapping("/musicPlayer")
public class MusicPlayerController {

    @Resource
    private MusicPlayerService musicPlayerService;

    @ApiOperation(value = "分页查询音乐列表")
    @PostMapping("/findMusicPage")
    public R<Map<String, Object>> findMusicPage(@Valid @RequestBody MusicPageQO qo) {
        return ResultUtil.success(musicPlayerService.findMusicPage(qo));
    }

    @ApiOperation(value = "查询音乐列表")
    @PostMapping("/findMusicList")
    public R<List<MusicPlayerVO>> findMusicList(@Valid @RequestBody ModuleIdQO qo) {
        return ResultUtil.success(musicPlayerService.findMusicList(qo.getModuleId()));
    }

    @ApiOperation(value = "添加音乐")
    @PostMapping("/addMusic")
    public R<Boolean> addMusic(@Valid @RequestBody MusicPlayer musicPlayer) {
        boolean flag = musicPlayerService.save(musicPlayer);
        return ResultUtil.success(flag);
    }

    @ApiOperation(value = "修改音乐")
    @PostMapping("/updateMusic")
    public R<Boolean> updateMusic(@Valid @RequestBody MusicPlayer musicPlayer) {
        boolean flag = musicPlayerService.updateById(musicPlayer);
        return ResultUtil.success(flag);
    }
}
